<?php

namespace App\Console\Commands;

use App\Models\ChallengeGame;
use App\Models\Report;
use App\Models\Reservation;
use Carbon\Carbon;
use Illuminate\Console\Command;

class UpdateViewNum extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update:viewnum';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '更新对战，约战观看数';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $end = Carbon::now()->subHour();
        $start = Carbon::now()->subHours(2);

        $num = mt_rand(10, 15);

        Reservation::whereBetween('created_at', [$start, $end])->increment('view', $num);
        ChallengeGame::whereBetween('created_at', [$start, $end])->increment('view', $num);

        $reportNum = mt_rand(1000, 3000);
        Report::whereBetween('created_at', [$start, $end])->increment('view', $reportNum);

        $this->info("执行成功");

    }
}
